package 第3节函数;
//1~100求和 递归
public class RecursionDemo01 {
    public static void main(String[] args) {
        System.out.println(f(100));
    }
    /*
f(100) = 1+2+3+4+.....+97+98+99+100
f(100) = f(99) + 100
f(99) = f(98) + 99
f(98) = f(97) + 98
...
f(3) = f(2) + 3     3 + 3 = 6
f(2) = f(1) + 2     1 + 3 = 3
f(1) = 1
        1, x = 1
f(x)
        f(x-1) + x, x > 1
*/
    public static int f(int x) {
        if (x == 1) {
            return 1;
        }
        return f(x - 1) + x;
    }
}

